﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using KeRui.BLL;
using KeRui.Common;
using KeRui.TemplateMaker;

public partial class Manage_Cms_HtmlCreate : Page
{
    protected readonly string Act = ManageHelper.PageAct();
    protected string pagetext = string.Empty;
    protected string pagetexttab = string.Empty;
    protected bool IsShowGetKeywords, IsShowEditor;
    protected int SiteID = PageRequest.GetInt("siteid", -1);
    protected void Page_Load(object sender, EventArgs e)
    {
        //site_htmlindex
        //检查登录HYC
        ManageHelper.CheckAdminLogin();
        switch (Act)
        {
            case "index": //首页
                pagetext = "点击生成首页生成网站首页页面";
                pagetexttab = "首页";
                break;
            case "node":
                pagetext = "选择需要生成栏目页面的栏目后点击“生成选定内容”即可生成对应的栏目页面。"; //栏目动态生成
                pagetexttab = "栏目";
                switch (PageRequest.GetString("buttom"))
                {
                    case "publish":
                        switch (PageRequest.GetString("sub"))
                        {
                            case "生成选定内容":
                                string nodeIDCollection = PageRequest.GetString("NodeIDCollectionToCreate");
                                if (!string.IsNullOrEmpty(nodeIDCollection))
                                {
                                    Response.Redirect("HtmlCreateProgress.aspx?act=node&nodeids=" + nodeIDCollection + "&siteid=" + SiteID);
                                    Response.End();
                                }
                                else
                                {
                                    Response.Redirect("HtmlCreate.aspx?siteid=" + SiteID +
                                                      "&act=node&errormsg=请首先选中希望生成的节点！");
                                    Response.End();
                                }
                                break;
                        }
                        break;
                }
                break;
            case "content":
                pagetext = "选择需要生成内容页面的栏目后点击“生成选定内容”即可生成对应的内容页面。";
                pagetexttab = "内容";
                switch (PageRequest.GetString("buttom"))
                {
                    case "publish":
                        switch (PageRequest.GetString("sub"))
                        {
                            case "生成选定内容":
                                string nodeIDCollection = PageRequest.GetString("NodeIDCollectionToCreate");
                                if (!string.IsNullOrEmpty(nodeIDCollection))
                                {
                                    if (PageRequest.GetString("timechose")=="on")
                                    {
                                        string time = PageRequest.GetString("txtCreateTime");
                                        Response.Redirect("HtmlCreateProgress.aspx?act=content&siteid=" + SiteID + "&nodeids=" + nodeIDCollection + "&time=" + time);
                                    }
                                    else
                                    {
                                        Response.Redirect("HtmlCreateProgress.aspx?act=content&siteid=" + SiteID + "&nodeids=" + nodeIDCollection);
                                    }
                                    Response.End();
                                }
                                else
                                {
                                    Response.Redirect("HtmlCreate.aspx?siteid=" + SiteID +
                                                      "&act=content&errormsg=请首先选中希望生成内容页面的栏目！");
                                    Response.End();
                                }
                                break;
                        }
                        break;
                }
                break;
        }
    }

    #region 栏目下拉列表

    protected static string SelectNodeList(int pId, int intTemp)
    {
        string RetStr = "";
        CmsNode bllCmsNode = new CmsNode();
        List<KeRui.Model.CmsNode> list = bllCmsNode.GetListByPId(pId, PageRequest.GetInt("siteid", -1));
        int j = 0;
        foreach (KeRui.Model.CmsNode model in list)
        {
            j++;
            string Empty = "";
            for (int i = 0; i < model.Depth; i++)
            {
                Empty += "　";
            }
            if (model.NodeID == intTemp)
            {
                RetStr += "<option value=" + model.NodeID + " selected>" + Empty + "{0}" + model.NodeName + "</option>";
            }
            else
            {
                RetStr += "<option value=" + model.NodeID + ">" + Empty + "{0}" + model.NodeName + "</option>";
            }
            if (model.ChildNum > 0)
            {
                RetStr += SelectNodeList(model.NodeID, intTemp);
            }
            if (j == list.Count)
            {
                RetStr = RetStr.Replace("{0}", "└");
            }
            else
            {
                RetStr = RetStr.Replace("{0}", "├");
            }
        }
        return RetStr;
    }

    #endregion
}